<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="客户ID" prop="customerUid">
      <el-input v-model="dataForm.customerUid" placeholder="客户ID"></el-input>
    </el-form-item>
    <el-form-item label="买手ID" prop="buyerUid">
      <el-input v-model="dataForm.buyerUid" placeholder="买手ID"></el-input>
    </el-form-item>
    <el-form-item label="品牌" prop="brand">
      <el-input v-model="dataForm.brand" placeholder="品牌"></el-input>
    </el-form-item>
    <el-form-item label="分类" prop="type">
      <el-input v-model="dataForm.type" placeholder="分类"></el-input>
    </el-form-item>
    <el-form-item label="货号" prop="sku">
      <el-input v-model="dataForm.sku" placeholder="货号"></el-input>
    </el-form-item>
    <el-form-item label="颜色" prop="color">
      <el-input v-model="dataForm.color" placeholder="颜色"></el-input>
    </el-form-item>
    <el-form-item label="尺寸" prop="size">
      <el-input v-model="dataForm.size" placeholder="尺寸"></el-input>
    </el-form-item>
    <el-form-item label="价格" prop="price">
      <el-input v-model="dataForm.price" placeholder="价格"></el-input>
    </el-form-item>
    <el-form-item label="优惠总金额" prop="discountPrice">
      <el-input v-model="dataForm.discountPrice" placeholder="优惠总金额"></el-input>
    </el-form-item>
    <el-form-item label="购买总数量" prop="number">
      <el-input v-model="dataForm.number" placeholder="购买总数量"></el-input>
    </el-form-item>
    <el-form-item label="收货时间" prop="reciveTime">
      <el-input v-model="dataForm.reciveTime" placeholder="收货时间"></el-input>
    </el-form-item>
    <el-form-item label="描述" prop="description">
      <el-input v-model="dataForm.description" placeholder="描述"></el-input>
    </el-form-item>
    <el-form-item label="地址" prop="address">
      <el-input v-model="dataForm.address" placeholder="地址"></el-input>
    </el-form-item>
    <el-form-item label="电话" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="电话"></el-input>
    </el-form-item>
    <el-form-item label="收货人" prop="reciveName">
      <el-input v-model="dataForm.reciveName" placeholder="收货人"></el-input>
    </el-form-item>
    <el-form-item label="订单状态：0-下单，1-填完收货地址和密语，等待付款，2-已付款，待发货，3-原状态买手完善信息，9-上传购买凭证，10-上传打包信息，4,-已发货，待收货，5-确认收货，待评价，6-买手已评价客人没有评价，7-客人评价买手没有评价，8,-订单完成，11-交易关闭（由于缺货导致），-1 - 客人取消订单" prop="status">
      <el-input v-model="dataForm.status" placeholder="订单状态：0-下单，1-填完收货地址和密语，等待付款，2-已付款，待发货，3-原状态买手完善信息，9-上传购买凭证，10-上传打包信息，4,-已发货，待收货，5-确认收货，待评价，6-买手已评价客人没有评价，7-客人评价买手没有评价，8,-订单完成，11-交易关闭（由于缺货导致），-1 - 客人取消订单"></el-input>
    </el-form-item>
    <el-form-item label="订单号" prop="orderNo">
      <el-input v-model="dataForm.orderNo" placeholder="订单号"></el-input>
    </el-form-item>
    <el-form-item label="省市区" prop="province">
      <el-input v-model="dataForm.province" placeholder="省市区"></el-input>
    </el-form-item>
    <el-form-item label="发布的商品id" prop="publishId">
      <el-input v-model="dataForm.publishId" placeholder="发布的商品id"></el-input>
    </el-form-item>
    <el-form-item label="标记是客人发布商品还是客人下买手单" prop="flag">
      <el-input v-model="dataForm.flag" placeholder="标记是客人发布商品还是客人下买手单"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createdAt">
      <el-input v-model="dataForm.createdAt" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updatedAt">
      <el-input v-model="dataForm.updatedAt" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="额外的金额" prop="morePrice">
      <el-input v-model="dataForm.morePrice" placeholder="额外的金额"></el-input>
    </el-form-item>
    <el-form-item label="密语" prop="miyu">
      <el-input v-model="dataForm.miyu" placeholder="密语"></el-input>
    </el-form-item>
    <el-form-item label="到货时间" prop="days">
      <el-input v-model="dataForm.days" placeholder="到货时间"></el-input>
    </el-form-item>
    <el-form-item label="邮编" prop="zipCode">
      <el-input v-model="dataForm.zipCode" placeholder="邮编"></el-input>
    </el-form-item>
    <el-form-item label="订单表格修改之前和之后的标志，1：旧订单，2：新订单" prop="diffFlag">
      <el-input v-model="dataForm.diffFlag" placeholder="订单表格修改之前和之后的标志，1：旧订单，2：新订单"></el-input>
    </el-form-item>
    <el-form-item label="运费" prop="freight">
      <el-input v-model="dataForm.freight" placeholder="运费"></el-input>
    </el-form-item>
    <el-form-item label="商品评分" prop="goodGrade">
      <el-input v-model="dataForm.goodGrade" placeholder="商品评分"></el-input>
    </el-form-item>
    <el-form-item label="导购评分" prop="guideGrade">
      <el-input v-model="dataForm.guideGrade" placeholder="导购评分"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          customerUid: '',
          buyerUid: '',
          brand: '',
          type: '',
          sku: '',
          color: '',
          size: '',
          price: '',
          discountPrice: '',
          number: '',
          reciveTime: '',
          description: '',
          address: '',
          phone: '',
          reciveName: '',
          status: '',
          orderNo: '',
          province: '',
          publishId: '',
          flag: '',
          createdAt: '',
          updatedAt: '',
          morePrice: '',
          miyu: '',
          days: '',
          zipCode: '',
          diffFlag: '',
          freight: '',
          goodGrade: '',
          guideGrade: ''
        },
        dataRule: {
          customerUid: [
            { required: true, message: '客户ID不能为空', trigger: 'blur' }
          ],
          buyerUid: [
            { required: true, message: '买手ID不能为空', trigger: 'blur' }
          ],
          brand: [
            { required: true, message: '品牌不能为空', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '分类不能为空', trigger: 'blur' }
          ],
          sku: [
            { required: true, message: '货号不能为空', trigger: 'blur' }
          ],
          color: [
            { required: true, message: '颜色不能为空', trigger: 'blur' }
          ],
          size: [
            { required: true, message: '尺寸不能为空', trigger: 'blur' }
          ],
          price: [
            { required: true, message: '价格不能为空', trigger: 'blur' }
          ],
          discountPrice: [
            { required: true, message: '优惠总金额不能为空', trigger: 'blur' }
          ],
          number: [
            { required: true, message: '购买总数量不能为空', trigger: 'blur' }
          ],
          reciveTime: [
            { required: true, message: '收货时间不能为空', trigger: 'blur' }
          ],
          description: [
            { required: true, message: '描述不能为空', trigger: 'blur' }
          ],
          address: [
            { required: true, message: '地址不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '电话不能为空', trigger: 'blur' }
          ],
          reciveName: [
            { required: true, message: '收货人不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '订单状态：0-下单，1-填完收货地址和密语，等待付款，2-已付款，待发货，3-原状态买手完善信息，9-上传购买凭证，10-上传打包信息，4,-已发货，待收货，5-确认收货，待评价，6-买手已评价客人没有评价，7-客人评价买手没有评价，8,-订单完成，11-交易关闭（由于缺货导致），-1 - 客人取消订单不能为空', trigger: 'blur' }
          ],
          orderNo: [
            { required: true, message: '订单号不能为空', trigger: 'blur' }
          ],
          province: [
            { required: true, message: '省市区不能为空', trigger: 'blur' }
          ],
          publishId: [
            { required: true, message: '发布的商品id不能为空', trigger: 'blur' }
          ],
          flag: [
            { required: true, message: '标记是客人发布商品还是客人下买手单不能为空', trigger: 'blur' }
          ],
          createdAt: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updatedAt: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          morePrice: [
            { required: true, message: '额外的金额不能为空', trigger: 'blur' }
          ],
          miyu: [
            { required: true, message: '密语不能为空', trigger: 'blur' }
          ],
          days: [
            { required: true, message: '到货时间不能为空', trigger: 'blur' }
          ],
          zipCode: [
            { required: true, message: '邮编不能为空', trigger: 'blur' }
          ],
          diffFlag: [
            { required: true, message: '订单表格修改之前和之后的标志，1：旧订单，2：新订单不能为空', trigger: 'blur' }
          ],
          freight: [
            { required: true, message: '运费不能为空', trigger: 'blur' }
          ],
          goodGrade: [
            { required: true, message: '商品评分不能为空', trigger: 'blur' }
          ],
          guideGrade: [
            { required: true, message: '导购评分不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/biz/orders/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.customerUid = data.orders.customerUid
                this.dataForm.buyerUid = data.orders.buyerUid
                this.dataForm.brand = data.orders.brand
                this.dataForm.type = data.orders.type
                this.dataForm.sku = data.orders.sku
                this.dataForm.color = data.orders.color
                this.dataForm.size = data.orders.size
                this.dataForm.price = data.orders.price
                this.dataForm.discountPrice = data.orders.discountPrice
                this.dataForm.number = data.orders.number
                this.dataForm.reciveTime = data.orders.reciveTime
                this.dataForm.description = data.orders.description
                this.dataForm.address = data.orders.address
                this.dataForm.phone = data.orders.phone
                this.dataForm.reciveName = data.orders.reciveName
                this.dataForm.status = data.orders.status
                this.dataForm.orderNo = data.orders.orderNo
                this.dataForm.province = data.orders.province
                this.dataForm.publishId = data.orders.publishId
                this.dataForm.flag = data.orders.flag
                this.dataForm.createdAt = data.orders.createdAt
                this.dataForm.updatedAt = data.orders.updatedAt
                this.dataForm.morePrice = data.orders.morePrice
                this.dataForm.miyu = data.orders.miyu
                this.dataForm.days = data.orders.days
                this.dataForm.zipCode = data.orders.zipCode
                this.dataForm.diffFlag = data.orders.diffFlag
                this.dataForm.freight = data.orders.freight
                this.dataForm.goodGrade = data.orders.goodGrade
                this.dataForm.guideGrade = data.orders.guideGrade
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/biz/orders/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'customerUid': this.dataForm.customerUid,
                'buyerUid': this.dataForm.buyerUid,
                'brand': this.dataForm.brand,
                'type': this.dataForm.type,
                'sku': this.dataForm.sku,
                'color': this.dataForm.color,
                'size': this.dataForm.size,
                'price': this.dataForm.price,
                'discountPrice': this.dataForm.discountPrice,
                'number': this.dataForm.number,
                'reciveTime': this.dataForm.reciveTime,
                'description': this.dataForm.description,
                'address': this.dataForm.address,
                'phone': this.dataForm.phone,
                'reciveName': this.dataForm.reciveName,
                'status': this.dataForm.status,
                'orderNo': this.dataForm.orderNo,
                'province': this.dataForm.province,
                'publishId': this.dataForm.publishId,
                'flag': this.dataForm.flag,
                'createdAt': this.dataForm.createdAt,
                'updatedAt': this.dataForm.updatedAt,
                'morePrice': this.dataForm.morePrice,
                'miyu': this.dataForm.miyu,
                'days': this.dataForm.days,
                'zipCode': this.dataForm.zipCode,
                'diffFlag': this.dataForm.diffFlag,
                'freight': this.dataForm.freight,
                'goodGrade': this.dataForm.goodGrade,
                'guideGrade': this.dataForm.guideGrade
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
